package com.fancy.music.config;

import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@RequiredArgsConstructor
public class StaticResourceConfig implements WebMvcConfigurer {

    private final FileUploadConfig fileUploadConfig;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 配置文件访问路径映射
        registry.addResourceHandler("/files/**")
                .addResourceLocations("file:" + fileUploadConfig.getBasePath());

        // 音频文件访问
        registry.addResourceHandler("/audio/**")
                .addResourceLocations("file:" + fileUploadConfig.getBasePath() + fileUploadConfig.getAudioPath());

        // 封面图片访问
        registry.addResourceHandler("/covers/**")
                .addResourceLocations("file:" + fileUploadConfig.getBasePath() + fileUploadConfig.getCoverPath());

        // 歌词文件访问
        registry.addResourceHandler("/lyrics/**")
                .addResourceLocations("file:" + fileUploadConfig.getBasePath() + fileUploadConfig.getLyricPath());
    }
}
